﻿@model SAIM.Models.RolesUsersViewModel
@using SAIM.Models;
@using SAIM.Models.BLL
@{
    ViewBag.Title = "Roles de usuario";
}

@section css {
    <style>
    .section {
        min-height:210px;
        padding: 0px;
    }
    </style>
}

<h2>@ViewBag.Title</h2>  
<p class="text-success">@ViewBag.StatusMessage</p>
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="panel panel-default table-responsive">
    <ul class="list-group col-xs-12" style="padding-left:15px;">
        <li class="list-group-item list-group-item-text"><b>Información del usuario</b> [ <a href="@Url.Action("Manage")/?id=@Model.Id">Regresar</a> ]</li>
        <li class="list-group-item" style="border-bottom: none;">
            <dl class="dl-horizontal">
                <dt>UPN:</dt>
                <dd>@Model.Id</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>Nombre:</dt>
                <dd>@Model.UserName</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>Correo electrónico:</dt>
                <dd>@Model.Email</dd>
            </dl>
            <dl class="dl-horizontal">
                <dt>Perfil:</dt>
                @{
                    if (Model.Profile != string.Empty)
                    {
                        <dd>@Model.Profile</dd>
                    }
                    else
                    {
                        <dd>Sin perfil asignado</dd>
                    }
                }
            </dl>
        </li>
    </ul>
</div>
@using (Html.BeginForm("Roles", "Users", FormMethod.Post, new { role = "form" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(u => u.Id)
@Html.HiddenFor(u => u.NewRole)
@Html.HiddenFor(u => u.RemoveRole)
<div class="row">
    <nav class="col-sm-4" id="myScrollspy">
        <ul class="nav nav-pills nav-stacked">
            <li id="nav-section1" class="active"><a href="#section1">Perfil de usuario</a></li>
            <li id="nav-section2"><a href="#section2">Administración</a></li>
            <li id="nav-section4"><a href="#section4">Mantenimiento</a></li>
            <li id="nav-section3"><a href="#section3">TIC´S</a></li>
            <li id="nav-section5"><a href="#section5">General</a></li>
            <li id="nav-section6"><a href="#section6">Servicio Social</a></li>
        </ul>
    </nav>
    <div class="col-sm-8">
        @using (AspNetUsersBLL user = new AspNetUsersBLL(Model.Id))
        {
            <div class="panel panel-default" style="max-height:210px; overflow:auto;">
                <ul class="list-group">
                    <li id="section1" class="list-group-item section">
                        <ul class="list-group">
                            <li class="list-group-item list-group-item-info">
                                <h4 style="margin-top: 0px; margin-bottom:0px;">Roles de usuario</h4>
                            </li>
                            <li class="list-group-item">
                                <table class="table table-hover">
                                    <tbody>
                                        @if (user.GetUserRoles().Count > 0)
                                        {
                                            foreach (AspNetRoles role in user.GetUserRoles())
                                            {
                                                <tr>
                                                    <td>
                                                        <div class="col-sm-9"><h5>@role.Name</h5></div>
                                                        <div class="col-sm-3"><button type="submit" class="btn-remove-role btn btn-danger pull-right" data-role="@role.RealName"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Eliminar</button></div>
                                                    </td>
                                                </tr>
                                            }
                                        }
                                        else
                                        {
                                            <tr class="danger">
                                                <td>
                                                    <div class="col-sm-9"><h5>Sin roles de usuario</h5></div>
                                                </td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </li>
                        </ul>
                    </li>
                    <li id="section2" class="list-group-item section">
                        <ul class="list-group">
                            <li class="list-group-item list-group-item-info">
                                <h4 style="margin-top: 0px; margin-bottom:0px;">Roles Administración</h4>
                            </li>
                            <li class="list-group-item">
                                <table class="table table-hover">
                                    <tbody>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>Administrar tickets (Administración)</h5></div>
                                                @if (!user.isInRole("Administration Tickets"))
                                                {
                                                <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="Administration Tickets"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </li>
                        </ul>
                    </li>
                    <li id="section4" class="list-group-item section">
                        <ul class="list-group">
                            <li class="list-group-item list-group-item-info">
                                <h4 style="margin-top: 0px; margin-bottom:0px;">Roles Mantenimiento</h4>
                            </li>
                            <li class="list-group-item">
                                <table class="table table-hover">
                                    <tbody>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>Administrar tickets (Mantenimiento)</h5></div>
                                                @if (!user.isInRole("Maintenance Tickets"))
                                                {
                                                    <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="Maintenance Tickets"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </li>
                        </ul>
                    </li>
                    <li id="section3" class="list-group-item section">
                        <ul class="list-group">
                            <li class="list-group-item list-group-item-info">
                                <h4 style="margin-top: 0px; margin-bottom:0px;">Roles TIC´S</h4>
                            </li>
                            <li class="list-group-item">
                                <table class="table table-hover">
                                    <tbody>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>Buscar Usuarios</h5></div>
                                                @if (!user.isInRole("Search users"))
                                                { 
                                                <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="Search users"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>Administrar tickets (TIC'S)</h5></div>
                                                @if (!user.isInRole("RTIC Tickets"))
                                                {
                                                <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="RTIC Tickets"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </li>
                        </ul>
                    </li>
                    <li id="section5" class="list-group-item section">
                        <ul class="list-group">
                            <li class="list-group-item list-group-item-info">
                                <h4 style="margin-top: 0px; margin-bottom:0px;">Roles Generales</h4>
                            </li>
                            <li class="list-group-item">
                                <table class="table table-hover">
                                    <tbody>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>@SAIM.Resources.Site.Createtickets</h5></div>
                                                @if (!user.isInRole("Create tickets"))
                                                {
                                                    <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="Create tickets"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>@SAIM.Resources.Site.Lists</h5></div>
                                                @if (!user.isInRole("Lists"))
                                                {
                                                    <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="Lists"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>@SAIM.Resources.Site.CreateLists</h5></div>
                                                @if (!user.isInRole("Create Lists"))
                                                {
                                                    <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="Create Lists"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>@SAIM.Resources.Site.Managetickets</h5></div>
                                                @if (!user.isInRole("Manage tickets"))
                                                {
                                                    <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="Manage tickets"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </li>
                        </ul>
                    </li>
                    <li id="section6" class="list-group-item section">
                        <ul class="list-group">
                            <li class="list-group-item list-group-item-info">
                                <h4 style="margin-top: 0px; margin-bottom:0px;">Roles Servicio Social</h4>
                            </li>
                            <li class="list-group-item">
                                <table class="table table-hover">
                                    <tbody>
                                        <tr>
                                            <td>
                                                <div class="col-sm-9"><h5>Servicio Social(Capturar y Consultar)</h5></div>
                                                @if (!user.isInRole("Social Service"))
                                                {
                                                    <div class="col-sm-3"><button type="submit" class="btn-add-role btn btn-success pull-right" data-role="Social Service"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Agregar</button></div>
                                                }
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        }
    </div>
</div>
}
@section Scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            $('[id^=section]').mouseover(function () {
                var nav = '#nav-' + $(this).attr('id');
                $('[id^=nav-]').removeClass('active');
                $(nav.toString()).addClass('active');
            });

            $('[id^=section]').focus(function () {
                var nav = '#nav-' + $(this).attr('id');
                $('[id^=nav-]').removeClass('active');
                $(nav.toString()).addClass('active');
            });

            $('[id^=nav-]').bind('click', function () {
                $('[id^=nav-]').removeClass('active');
                $(this).addClass('active');
            });

            $(window).on('hashchange', function () {
                var nav = '#nav-' + window.location.hash.replace('#', '');
                $('[id^=nav-]').removeClass('active');
                $(nav.toString()).addClass('active');
            });

            $('.btn-add-role').bind('click', function () {
                $('#NewRole').val($(this).data('role'));
                $('#RemoveRole').val('False');
            });

            $('.btn-remove-role').bind('click', function () {
                $('#NewRole').val($(this).data('role'));
                $('#RemoveRole').val('True');
            });

            window.location.hash = '#section1';
        });
    </script>    
}